<%--
  Created by IntelliJ IDEA.
  User: w1057229265
  Date: 2021/5/25
  Time: 9:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.9.15/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.9.15/themes/icon.css">
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.9.15/jquery.min.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.9.15/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.9.15/locale/easyui-lang-zh_CN.js"></script>
    <script> $(function () {
        loadData('');
        // $('#dg').datagrid({
        //     url: '/ServletSupplier?action=getdglist',
        //     toolbar: '#tb',
        //     pagination: true,
        //     fit: true,
        //     singleSelect: true,
        //     columns: [[
        //         {field: 'supplierno', title: '供应商编码', width: 100},
        //         {field: 'suppliername', title: '供应商名称', width: 400},
        //         {field: 'contacts', title: '联系人', width: 100},
        //         {field: 'telephone', title: '电话', width: 100},
        //         {field: 'address', title: '地址'}
        //     ]]
        // });
        //
        $('#btnAdd').click(function () {
            $('#dd').dialog({
                title: '新增数据',
                width: 480,
                height: 310,
                closed: false,
                cache: false,
                href: 'supplierform.jsp?action=add',
                modal: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        let isOK = $('#form').form('validate');
                        if (isOK) {
                            $.messager.confirm('确认', '是否确认添加', function (r) {
                                if (r) {
                                    SaveData('add');
                                }
                            });
                        }

                    }
                }, {
                    text: '退出',
                    iconCls: 'icon-back',
                    handler: function () {
                        $('#dd').dialog('close');


                    }
                }]
            });
        })
        $('#btnDelete').click(function () {
            $.messager.confirm('提示', '是否要删除该数据？', function (r) {
                if (r) {
                    let row = $('#dg').datagrid("getSelected");
                    $.ajax({
                        type: "GET",
                        url: "/ServletSupplier?action=delete",
                        data: {supplierno: row.supplierno},
                        success: function (ret) {
                            let result = eval("(" + ret + ")");
                            if (result.code == "200") {
                                $.messager.show({
                                    title: '提示',
                                    msg: result.msg,
                                    showType: 'show',
                                    timeout: 2000,
                                    showType: 'slide'
                                });
                                $('#dg').datagrid('reload');
                            } else {
                                $.messager.alert('提示', result.msg, 'warning');

                            }

                        }
                    })
                }
            })
        })
        $('#btnEdit').click(function () {
            if ($('#dg').datagrid('getSelected') == null) {
                $.messager.alert("提示", "请选择要编辑的数据", 'warning')
                return;
            }
            $('#dd').dialog({
                title: '修改数据',
                width: 480,
                height: 310,
                closed: false,
                cache: false,
                href: 'supplierform.jsp?action=edit',
                modal: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        let isOK = $('#ff').form('validate');
                        if (isOK) {
                            $.messager.confirm('确认', '是否确认修改', function (r) {
                                if (r) {
                                    SaveData('update');
                                }
                            });
                        }

                    }
                }, {
                    text: '退出',
                    iconCls: 'icon-back',
                    handler: function () {

                    }
                }]
            });
        })
        $('#BtnQuery').textbox({
            onClickButton:function (){
                alert($(this).val())
                loadData($(this).val())
            }
        })
        function SaveData(action) {
            $.messager.progress();	// display the progress bar
            $('#ff').form('submit', {
                url: '/ServletSupplier?action=' + action,
                onSubmit: function () {
                    var isValid = $(this).form('validate');
                    if (!isValid) {
                        $.messager.progress('close');	// hide progress bar while the form is invalid
                    } else {

                    }
                    return isValid;	// return false will stop the form submission
                },
                success: function (data) {
                    let result = eval("(" + data + ")");
                    dataType:'json'
                    if (result.code == '200') {
                        $.messager.alert('提示', result.msg, 'info');
                        $('#dd').dialog('close');
                        $('#dg').datagrid('reload');
                    } else
                        $.messager.alert('提示', result.msg, 'warning');
                    $.messager.progress('close');

                }
            });
        }
        function  loadData(val){

            $('#dg').datagrid({
                url: '/ServletSupplier?action=getdglist',
                toolbar: '#tb',
                pagination: true,
                fit: true,
                singleSelect: true,
                queryParams: {
                    suppliername: val
                },
                columns: [[
                    {field: 'supplierno', title: '供应商编码', width: 100},
                    {field: 'suppliername', title: '供应商名称', width: 400},
                    {field: 'contacts', title: '联系人', width: 100},
                    {field: 'telephone', title: '电话', width: 100},
                    {field: 'address', title: '地址'}
                ]]
            });
        }

    })
    </script>
</head>
<body class="easyui-layout">
<div data-options="region:'center',border:false">
    <table id="dg">

    </table>
</div>
<div id="dd"></div>
<div id="tb" style="height:auto">
    <table>
        <tr>
            <td><a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton"
                   data-options="iconCls:'icon-add',plain:true">添加</a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a id="btnEdit" href="javascript:void(0)" class="easyui-linkbutton"
                   data-options="iconCls:'icon-edit',plain:true">编辑</a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a id="btnDelete" href="javascript:void(0)" class="easyui-linkbutton"
                   data-options="iconCls:'icon-remove',plain:true">删除</a>
            </td>
            <td>
                <input id="BtnQuery" class="easyui-textbox" data-options="buttonText:'查询',buttonAlign:'right',buttonIcon:'icon-search',prompt:'供应商名称'" style="width:280px;">
            </td>
        </tr>
    </table>
</div>
</body>
</html>
